import * as cryptojs from 'crypto-js';

export class Secret {
  static encrypt(ePassword) {
    let secretKey = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
      /[xy]/g,
      (c) => {
        const r = (Math.random() * 16) | 0,
          v = c === 'x' ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      },
    );
    secretKey = secretKey + '---' + Math.random().toString(36).substr(2);
    const key = cryptojs.enc.Utf8.parse(secretKey);
    const srcs = cryptojs.enc.Utf8.parse(ePassword);
    const encryptCode = cryptojs.AES.encrypt(srcs, key, {
      mode: cryptojs.mode.ECB,
      padding: cryptojs.pad.Pkcs7,
    });
    return encryptCode.toString();
  }
}
